/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var detectCycle = function (head) {
  let first = head
  const useArr = []
  let res = null
  while (first !== null) {
    if (useArr.includes(first)) {
      res = true
      return first
    }
    useArr.push(first)
    first = first.next
  }
  return res
}
